cmake_minimum_required(VERSION 3.16)
project(middle)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_BUILD_TYPE Release)
#set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -O3 -Who-pmf-conversions -Who-format -fpermissive")
set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -O3 -fpermissive")


SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/output/bin)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/output/lib)

set(CJSON_PATH ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cJSON)

#SET(CMAKE_SYSTEM_NAME UNIX)
add_definitions(-DSPDLOG_ACTIVE_LEVEL=0x00) #开启spdlog宏打印的trace debug等级

if(LINUX)
    set(MIDD_PLATFORM ${CMAKE_CURRENT_SOURCE_DIR}/platform/linux)
elseif(QNX)
    set(MIDD_PLATFORM ${CMAKE_CURRENT_SOURCE_DIR}/platform/qnx)
elseif(APPLE)
    set(MIDD_PLATFORM ${CMAKE_CURRENT_SOURCE_DIR}/platform/mac)
elseif(WIN32)
    set(MIDD_PLATFORM ${CMAKE_CURRENT_SOURCE_DIR}/platform/win)
elseif(UNIX)
    set(MIDD_PLATFORM ${CMAKE_CURRENT_SOURCE_DIR}/platform/unix)
else()
    set(MIDD_PLATFORM ${CMAKE_CURRENT_SOURCE_DIR}/platform/unix)
endif()

# 平台文件包含
include_directories(${MIDD_PLATFORM}/include)
#set(PLATFORM_FILES ${MIDD_PLATFORM}/source/mman.cpp)
file(GLOB PLATFORM_FILES ${MIDD_PLATFORM}/source/*.cpp)

# 日志文件包含
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/logger/include)
file(GLOB LOGGER_FILES
        ${CMAKE_CURRENT_SOURCE_DIR}/logger/source/*.cpp
        )


# 设置源文件搜索规则
file(GLOB SOURCE_FILES
        ${CMAKE_CURRENT_SOURCE_DIR}/source/runtime/*.cpp
        )

add_library(${PROJECT_NAME}
        ${PLATFORM_FILES}
        ${SOURCE_FILES}
        ${LOGGER_FILES}
        )

if(LINUX)
    target_link_libraries(${PROJECT_NAME}
            PUBLIC
            rt
            pthread
            )
elseif(QNX)
    target_link_libraries(${PROJECT_NAME}
            PRIVATE
            socket
            )
elseif(APPLE)
elseif(WIN32)
elseif(UNIX)
    target_link_libraries(${PROJECT_NAME}
            PUBLIC
            rt
            pthread
            )
else()
    target_link_libraries(${PROJECT_NAME}
            PUBLIC
            rt
            pthread
            )
endif()

#file(COPY ${CJSON_PATH})
add_subdirectory(${CJSON_PATH})
